#pragma once

#include "Log.hpp"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>

class InetAddr
{
    using Self = InetAddr;
public:

    InetAddr(const struct sockaddr_in& addr)
        :_addr(addr)
        ,_port(ntohs(addr.sin_port))
        ,_ip(inet_ntoa(addr.sin_addr))
    {
        ;
    }

    bool operator==(const Self& other) const
    {
        return other._ip == _ip && other._port == _port;
    }

    std::string getStringAddr() const
    {
        return _ip + ":" + std::to_string(_port);
    }

    const struct sockaddr_in& getAddr() const
    {
        return _addr;
    }

    const std::string& getIp() const
    {
        return _ip;
    }

    uint16_t getPort() const
    {
        return _port;
    }

    ~InetAddr()
    {
        ;
    }

private:

    struct sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;

};
